package com.pn.controller;

import com.pn.entity.CurrentUser;
import com.pn.entity.OutStore;
import com.pn.entity.Result;
import com.pn.page.Page;
import com.pn.service.OutStoreService;
import com.pn.service.StoreService;
import com.pn.utils.TokenUtils;
import com.pn.utils.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/outstore")
@RestController
public class OutStoreController {

    @Autowired
    private OutStoreService outStoreService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private StoreService storeService;

    /*添加出库单接口/outstore/outstore-add*/
    @RequestMapping("/outstore-add")
    public Result addOutStore(@RequestBody OutStore outStore, @RequestHeader(WarehouseConstants.HEADER_TOKEN_NAME) String token) {
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
        outStore.setCreateBy(currentUser.getUserId());
        return outStoreService.saveOutStore(outStore);
    }

    /*查询所有仓库url接口/outstore/store-list*/
    @RequestMapping("/store-list")
    public Result storeList() {
        return Result.ok(storeService.queryAllStore());
    }

    /*分页查询出库单url接口/outstore-page-list*/
    @RequestMapping("/outstore-page-list")
    public Result queryOutStorePage(Page page, OutStore outStore) {
        page = outStoreService.queryOutStorePage(page, outStore);
        return Result.ok(page);
    }

    /*确认出库单url接口outstore/outstore-confirm*/
    @RequestMapping("/outstore-confirm")
    public Result outStoreConfirm(@RequestBody OutStore outStore) {
        return outStoreService.confirmOutStore(outStore);
    }

}
